/*
 * File:   ModelListHandlerTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "ModelListHandlerTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(ModelListHandlerTest);

ModelListHandlerTest::ModelListHandlerTest() {
}

ModelListHandlerTest::~ModelListHandlerTest() {
}

void ModelListHandlerTest::setUp() {
}

void ModelListHandlerTest::tearDown() {
}

void lowerCase(string& strToConvert) {
   for(unsigned int i=0; i < strToConvert.length(); i++) {
      strToConvert[i] = tolower(strToConvert[i]);
   }
}

void ModelListHandlerTest::testLowerCase() {
    string strToConvert1 = "Model1";
    string strToConvert2 = "MODEL2";
    
    lowerCase(strToConvert1);
    lowerCase(strToConvert2);
    
    if (strcmp(strToConvert1.c_str(), "model1") != 0 && strcmp(strToConvert2.c_str(), "model2") != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void ModelListHandlerTest::testGetModelList0() {
    ModelListHandler* modelListHandler0 = new ModelListHandler("model2 model1");
    vector<GenericModel*> result0 = modelListHandler0->getModelList();
    
    if (strcmp(result0[0]->getModelName().c_str(), "model1" ) != 0) {
        CPPUNIT_ASSERT(false); 
    }
    
    if(result0.size() != 2 ) {
        CPPUNIT_ASSERT(false);
    }
    
    if(strcmp(result0[1]->getModelName().c_str(), "model2" ) != 0) {
        CPPUNIT_ASSERT(false);    
    }
}

void ModelListHandlerTest::testGetModelList1() {
    ModelListHandler* modelListHandler1 = new ModelListHandler("model2 model2");
    vector<GenericModel*> result1 = modelListHandler1->getModelList();
    
    if (strcmp(result1[0]->getModelName().c_str(), "model2" ) != 0 || result1.size() != 1 ) {
        CPPUNIT_ASSERT(false);
    }
}

void ModelListHandlerTest::testGetModelList2() {
    string messageError = "ERROR ==> An invalid model gone passed as argument, verify it and try again.";
    try {
        ModelListHandler* modelListHandler2 = new ModelListHandler("model2 Model");
    }
    catch(InvalidModelException &ime) {
        if(strcmp(messageError.c_str(), ime.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void ModelListHandlerTest::testGetModelList3() {
    string messageError = "ERROR ==> An invalid model gone passed as argument, verify it and try again.";
    try {
        ModelListHandler* modelListHandler3 = new ModelListHandler("MODEL model4");
    }
    catch(InvalidModelException &ime) {
        if(strcmp(messageError.c_str(), ime.what()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void ModelListHandlerTest::testGetModelList4() {
    string messageError = "ERROR ==> An invalid model gone passed as argument, verify it and try again.";
    try {
        ModelListHandler* modelListHandler4 = new ModelListHandler("model2");
    }
    catch(InvalidModelException &ime) {
        if(strcmp(messageError.c_str(), ime.what()) == 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}
